local jiumeng_shenqu = fk.CreateSkill {

  name = "jiumeng_shenqu",

  tags = { Skill.Compulsory, },

}



jiumeng_shenqu:addEffect(fk.DamageInflicted, {
  name = "jiumeng_shenqu",
  anim_type = "defensive",
  priority = 1.1,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(jiumeng_shenqu.name) then
        return target and target == player
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
      local num = player:getMark("jiumeng_shenqu_inflect")
      if data.damage >= num then
        data.damage = num
        room:setPlayerMark(player,"jiumeng_shenqu_inflect",0)
      else
        room:removePlayerMark(player,"jiumeng_shenqu_inflect",data.damage)
      end
  end,
})

jiumeng_shenqu:addEffect(fk.TurnStart, {
  name = "jiumeng_shenqu",
  anim_type = "defensive",
  priority = 1.1,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(jiumeng_shenqu.name) then
        return true
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
      if player.shield > 0 then
        room:setPlayerMark(player,"jiumeng_shenqu_inflect",5)
      else
        room:setPlayerMark(player,"jiumeng_shenqu_inflect",3) 
      end
      if player.shield < 2 then
        room:changeShield(player,2-player.shield)
      end
  end,
})

jiumeng_shenqu:addEffect(fk.CardUsing, {
  name = "jiumeng_shenqu",
  anim_type = "defensive",
  priority = 1.1,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(jiumeng_shenqu.name) then
        return target and target == player
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
      room:addPlayerMark(player,"jiumeng_shenqu_draw",1)
      if player:getMark("jiumeng_shenqu_draw") == 2 then
        room:setPlayerMark(player,"jiumeng_shenqu_draw",0)
        return true
      end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
      player:drawCards(1,jiumeng_shenqu.name)
      room:recover{
        who = player,
        num = 1,
        skillName = jiumeng_shenqu.name,
        recoverBy = player,
      }
  end,
})

return jiumeng_shenqu